import React, { PureComponent, createRef } from 'react'

export class App extends PureComponent {
  constructor(){
    super()
    this.state = {

    }
    this.titleRef = createRef()
    this.titleEl = null
  }
  getH2DOM(){
    // 1.在react元素上绑定一个ref字符串
    // console.log(this.refs.inzv)

    // 2. 提前创建好ref对象,createRef(), 将创建出来的对象绑定到元素
    console.log(this.titleRef.current)

    // 3.
    console.log(this.titleEl)

  }
  render() {
    return (
      <div>
        <h2 ref="inzv">hello world</h2>
        <h2 ref={this.titleRef}>你好 inzv</h2>
        <h2 ref={el=>{this.titleEl = el}}>hello inzv</h2>
        <button onClick={ e=> this.getH2DOM()}>获取dom</button>
      </div>
    )
  }
}

export default App